enum CacheType{
  session,
  local
}
class CacheTool{
  
  // Storage: This Web Storage API interface provides access to a particular domain's session or local storage.
  storage: Storage
  
  constructor(type:CacheType){
    console.log("type: ",type)
    console.log("CacheType: ",CacheType)
    console.log("CacheType.local: ",CacheType.local)
    console.log("CacheType.session: ",CacheType.session)
    this.storage = type === 0 ? sessionStorage : localStorage
  }

  setCache(key:string,value:any){
    console.log("CacheTool.storage: ",CacheTool.storage)
    if(value){
      this.storage.setItem(key,JSON.stringify(value))
    }
  }

  getCache(key:string){
    const value = this.storage.getItem(key)
    if(value){
      return JSON.parse(value)
    }
  }

  removeCache(key:string){
    this.storage.removeItem(key)
  }

  clearCache(){
    this.storage.clear()
  }

}

const localCache = new CacheTool(CacheType.local)
const sessionCache = new CacheTool(CacheType.session)

export{localCache,sessionCache}